package com.ycu.jk16.mall.dao;

import static com.ycu.jk16.mall.util.common.AndroidMalConstant.PRODUCTTABLE;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.ycu.jk16.mall.dao.provider.ProductDynaSqlProvider;
import com.ycu.jk16.mall.domain.Product;

public interface ProductDao {
	@Select({ "select count(*) from " + PRODUCTTABLE })
	public Integer countProduct();

	@Select({ "select id from " + PRODUCTTABLE + " where name = #{NAME} order by id desc LIMIT 1" })
	public Integer lastProductId(@Param("NAME") String paramString);

	@Select({ "select * from " + PRODUCTTABLE + " where id = #{id}" })
	@Results({ @Result(column = "id", property = "id", id = true),
			@Result(column = "create_time", property = "createTime", javaType = java.util.Date.class),
			@Result(column = "update_time", property = "updateTime", javaType = java.util.Date.class),
			@Result(column = "category_id", property = "category", one = @One(select = "com.ycu.jk16.mall.dao.CategoryDao.selectById", fetchType = org.apache.ibatis.mapping.FetchType.EAGER)),
			@Result(column = "parentcategory_id", property = "parentCategory", one = @One(select = "com.ycu.jk16.mall.dao.ParentCategoryDao.selectById", fetchType = org.apache.ibatis.mapping.FetchType.EAGER)) })
	public Product selectById(@Param("id") Integer paramInteger);

	@SelectProvider(type = ProductDynaSqlProvider.class, method = "selectWhitParam")
	@Results({ @Result(column = "id", property = "id", id = true),
			@Result(column = "create_time", property = "createTime", javaType = java.util.Date.class),
			@Result(column = "update_time", property = "updateTime", javaType = java.util.Date.class),
			@Result(column = "category_id", property = "category", one = @One(select = "com.ycu.jk16.mall.dao.CategoryDao.selectById", fetchType = org.apache.ibatis.mapping.FetchType.EAGER)),
			@Result(column = "parentCategory_id", property = "parentCategory", one = @One(select = "com.ycu.jk16.mall.dao.ParentCategoryDao.selectById", fetchType = org.apache.ibatis.mapping.FetchType.EAGER)) })
	public List<Product> selectProductWithParam(Map<String, Object> paramMap);

	@SelectProvider(type = ProductDynaSqlProvider.class, method = "insertProduct")
	public void insertProduct(Product paramProduct);

	@SelectProvider(type = ProductDynaSqlProvider.class, method = "updateProduct")
	public void updateProduct(Product paramProduct);
}